package com.shangguosha.model;

import com.shangguosha.core.GameObject;
import com.shangguosha.model.enums.CardType;
import com.shangguosha.model.enums.Suit;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 卡牌抽象基类
 */
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class Card extends GameObject {
    protected CardType cardType;
    protected Suit suit;
    protected int number;
    protected String description;
    protected boolean isUsable;
    
    public Card(String id, String name, CardType cardType, Suit suit, int number) {
        super(id, name);
        this.cardType = cardType;
        this.suit = suit;
        this.number = number;
        this.isUsable = true;
        this.description = "";
    }
    
    public Card(String id, String name, CardType cardType, Suit suit, int number, String description) {
        super(id, name);
        this.cardType = cardType;
        this.suit = suit;
        this.number = number;
        this.description = description;
        this.isUsable = true;
    }
    
    /**
     * 检查卡牌是否可以使用
     */
    public abstract boolean canUse(Character player, Character target);
    
    /**
     * 使用卡牌
     */
    public abstract void use(Character player, Character target);
    
    /**
     * 获取卡牌效果描述
     */
    public abstract String getEffectDescription();
    
    /**
     * 克隆卡牌
     */
    public abstract Card clone();
    
    // 辅助方法
    public boolean isRed() {
        return suit != null && suit.isRed();
    }
    
    public boolean isBlack() {
        return suit != null && suit.isBlack();
    }
    
    public String getFullName() {
        if (suit != null && number > 0) {
            return String.format("%s%d %s", suit.getSymbol(), number, getName());
        }
        return getName();
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
        // 卡牌创建时的初始化逻辑
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        this.isUsable = false;
    }
    
    @Override
    public String toString() {
        return getFullName();
    }
}